<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>分步表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">宿舍</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="domitoryName"
                                                   placeholder="请输入" autocomplete="off" class="layui-input" id="domitoryName" required>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">充值度数:</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="usePower" value="60" id="usePower"
                                                   placeholder="请填写充值度数" class="layui-input" lay-verify="number" required>
                                        </div>
                                    </div>

                                    <!--一个假的支付方式,没啥用,也不存数据库-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">支付方式:</label>
                                        <div class="layui-input-block">
                                            <select lay-verify="required" id="whatPay" name="whatPay">
                                                <option value="微信">微信</option>
                                                <option value="支付宝">支付宝</option>
                                                <option value="现金" selected="selected">现金</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">宿舍:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="check-domitoryName">竹枫</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">剩余电量:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="surplusPower">100</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">充值度数:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux">
                                                <span style="font-size: 18px;color: #333;" id="check-usePower">10</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">付款方式:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="check-whatPay">人工入款</div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;确认充值&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        充值成功
                                    </div>
                                    <div style="font-size: 14px;color: #666;margin-top: 20px;">预计两小时到账</div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">再充一笔</button>
                                    <button class="layui-btn layui-btn-primary suc">完成</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--<hr>
                    <div style="color: #666;margin-top: 30px;margin-bottom: 40px;padding-left: 30px;">
                        <h3>说明</h3><br>
                        <h4>入款到保险箱</h4>
                        <p>如果需要，这里可以放一些关于产品的常见问题说明。</p>
                        <br><h4>入款到现金</h4>
                        <p>如果需要，这里可以放一些关于产品的常见问题说明。</p>
                    </div>-->
                </div>
            </div>
        </div>

    </div>
</div>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js?v=1.0.4}" charset="utf-8"></script>
<script language="JavaScript" th:inline="JavaScript">
    layui.use(['form', 'step', 'table', 'tableSelect', 'miniTab'], function () {
        var $ = layui.$,
            form = layui.form,
            step = layui.step,
            table = layui.table,
            tableSelect = layui.tableSelect,
            miniTab = layui.miniTab;

        var selectDomitory;
        var usePower;

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '填写充值信息'
            }, {
                title: '确认充值信息'
            }, {
                title: '完成'
            }]
        });

        tableSelect.render({
            elem: '#domitoryName',
            checkedKey: 'id',
            searchKey: 'name',
            table: {
                url: '../api-v1/domitory/search',
                cols: [ [
                    { type: 'radio' },
                    { field: 'id', title: 'ID' },
                    { field: 'name', title: '宿舍名' },
                    { field: 'surplusPower', title: '剩余电量' }
                ] ]
            },
            done: function (elem, data) {
                selectDomitory = data.data[0];
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.name)
                })
                elem.val(NEWJSON.join(","))
            }
        });


        form.on('submit(formStep)', function (data) {
            usePower = data.field.usePower;
            $("#check-domitoryName").text(selectDomitory.name);
            $("#surplusPower").text(selectDomitory.surplusPower);
            $("#check-whatPay").text(data.field.whatPay);
            step.next('#stepForm');
            return false;
        });

        form.on('submit(formStep2)', function (data) {
            $.ajax({
                url: "../api-v1/powerRecord/add",
                method: "post",
                data: {
                    domId: selectDomitory.id,
                    usePower: usePower
                },
                success: function (result) {
                    step.next('#stepForm');
                }
            });
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });

        $('.suc').click(function () {
            miniTab.deleteCurrentByIframe();
        });
    })
</script>
</body>
</html>